//Everything in this file was made by Travis Lamb A.2

#include <string>
#include <iostream>
#include <sstream>
#include "Date.h"
using namespace std;

//private method to make sure date is valid
bool Date::date_valid(int y, int m, int d)
{
	if(d>31 || d<1)
		return false;
	if(m>12 || m<1)
		return false;
	if(y<1760)
		return false;
	if(((m==4) || (m==6) || (m==9) || (m==11)) && (d>30))
		return false;
	if(m==2)
	{
		if((y%4)==0)
		{
			if(y%100!=0)
			{
				if(d>29)
					return false;
			}
			else if(y%400==0)
			{
				if(d>29)
					return false;
			}
			else if(d>28)
				return false;
		}
		else if(d>28)
			return false;
	}
	return true;
}

//Constructor simply calls set_date
Date::Date(int y, int m, int d)
{
	set_date(y,m,d);
}

//default constructor (unused
Date::Date(){}

//since this method is to_string, it returns a String. I may add a display method later (instead of returning a string, it actually couts stuff)
string Date::to_string_date()
{
	/*string temp;				//<-- This is old (read: BAD) code
	temp += "Year ";
	temp += (int)year;
	temp += ", Month ";
	temp += (int)month;
	temp += ", Day ";
	temp += (int)day;
	//return + "Year " + year + ", Month " + month + ", Day " + day;
	return temp;*/
	
	ostringstream oss;
	oss << "Year " << year << ", Month " << month << ", Day " << day;
	return oss.str();
}

//set_date is public so date can be changed later without needing to be reinitialized
void Date::set_date(int y, int m, int d)
{
	if(date_valid(y,m,d))	//insures valid date
	{
		Date::year = y;
		Date::month = m;
		Date::day = d;
	}
	else
		cerr << "\n\nERROR: Improper date input.\n\n";
}
